//
//  ViewController.m
//  10-UITableViewCell
//
//  Created by dllo on 16/7/27.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "ViewController.h"
#import "CustomTableViewCell.h"
#import "TestTableViewCell.h"
#import "NewsObject.h"
#define kTableViewReuse @"reuseIndentifier"
#define kTableViewCustionCellReuse @"cuestomReuse"
@interface ViewController ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *nameArr;
@property (nonatomic, strong) NSMutableArray *arr;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // 数据的传递依赖Model
    NewsObject *newsObject = [[NewsObject alloc] initWithNewsImage:@"10.jpg" title:@"为了污妖王" newsDescription:@"老王爱翻墙" newsNumberCount:@"8W"];
    self.arr = [NSMutableArray arrayWithObjects:newsObject, newsObject, newsObject, newsObject, nil];
    
//    NSArray *arr = @[@"唐益梦", @"张合尉", @"高雅馨", @"符淋淋", @"孙遥", @"李毅然", @"于瀚", @"沙长健", @"卢思彤", @"徐昊", @"曹冠雄", @"陈丹明", @"罗浩", @"肖扬", @"王道林", @"宫雪", @"李成", @"冀永金", @"姜浩", @"罗鹏飞", @"李昊林", @"郭宝", @"马峰", @"刘坦奇", @"殷明静", @"邓凯", @"徐康", @"王鍠", @"韩旭", @"杨睿", @"张信宝", @"姜程程", @"包铭礼", @"杜江", @"苗钧豪"];
//    self.nameArr = [NSMutableArray arrayWithArray:arr];
    self.tableView = [[UITableView alloc] initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    /* 使用自定义cell
     1 注册对应cell类型
     2 重用池取出对应cell类型
     3 自定义cell继承于UITableViewCell
     */
    [_tableView registerClass:[TestTableViewCell class] forCellReuseIdentifier:kTableViewReuse];
    [_tableView registerClass:[CustomTableViewCell class] forCellReuseIdentifier:kTableViewCustionCellReuse];
    // 多种cell混合使用 注册cell时, 注意重用标识不要相同
    [self.view addSubview:_tableView];
    self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
    [super setEditing:editing animated:animated];
    [_tableView setEditing:editing animated:animated];
}

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
    return UITableViewCellEditingStyleDelete;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _arr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 0) {
        CustomTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kTableViewCustionCellReuse];
        return cell;
    } else {
        TestTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kTableViewReuse];
        NewsObject *newsObject = _arr[indexPath.row];
        cell.newsObject = newsObject;
        return cell;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 100;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
